home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / dos / assignlock.c < prev    next >
C/C++ Source or Header  |  1996-09-12  |  3KB  |  131 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: assignlock.c,v 1.3 1996/08/13 13:52:44 digulla Exp $
  4.     $Log: assignlock.c,v $
  5.     Revision 1.3  1996/08/13 13:52:44  digulla
  6.     Replaced <dos/dosextens.h> by "dos_intern.h" or added "dos_intern.h"
  7.     Replaced __AROS_LA by __AROS_LHA
  8.  
  9.     Revision 1.2  1996/08/01 17:40:47  digulla
  10.     Added standard header for all files
  11.  
  12.     Desc:
  13.     Lang: english
  14. */
  15. #include <exec/memory.h>
  16. #include <clib/exec_protos.h>
  17. #include <dos/filesystem.h>
  18. #include "dos_intern.h"
  19.  
  20. /*****************************************************************************
  21.  
  22.     NAME */
  23.     #include <clib/dos_protos.h>
  24.  
  25.     __AROS_LH2(BOOL, AssignLock,
  26.  
  27. /*  SYNOPSIS */
  28.     __AROS_LHA(STRPTR, name, D1),
  29.     __AROS_LHA(BPTR,   lock, D2),
  30.  
  31. /*  LOCATION */
  32.     struct DosLibrary *, DOSBase, 102, Dos)
  33.  
  34. /*  FUNCTION
  35.     Create an assign from a given name to a lock. Replaces any older
  36.     assignments from that name, 0 cancels the assign completely. Do not
  37.     use or free the lock after calling this function - it becomes
  38.     the assign and will be freed by the system if the assign is removed.
  39.  
  40.     INPUTS
  41.     name - NUL terminated name of the assign.
  42.     lock - Lock to assigned directory.
  43.  
  44.     RESULT
  45.     !=0 success, 0 on failure. IoErr() gives additional information
  46.     in that case. The lock is freed on failure and must not be used
  47.     in that case too.
  48.  
  49.     NOTES
  50.  
  51.     EXAMPLE
  52.  
  53.     BUGS
  54.  
  55.     SEE ALSO
  56.  
  57.     INTERNALS
  58.  
  59.     HISTORY
  60.     29-10-95    digulla automatically created from
  61.                 dos_lib.fd and clib/dos_protos.h
  62.  
  63. *****************************************************************************/
  64. {
  65.     __AROS_FUNC_INIT
  66.     __AROS_BASE_EXT_DECL(struct DosLibrary *,DOSBase)
  67.  
  68.     BOOL success=1;
  69.     struct DosList *dl, *newdl=NULL;
  70.     struct Process *me=(struct Process *)FindTask(NULL);
  71.     struct IOFileSys io,*iofs=&io;
  72.     struct FileHandle *fh=(struct FileHandle *)BADDR(lock);
  73.  
  74.     if(lock)
  75.     {
  76.     newdl=MakeDosEntry(name,DLT_DIRECTORY);
  77.     if(newdl==NULL)
  78.     {
  79.         UnLock(lock);
  80.         me->pr_Result2=ERROR_NO_FREE_STORE;
  81.         return 0;
  82.     }else
  83.     {
  84.         newdl->dol_Unit  =fh->fh_Unit;
  85.         newdl->dol_Device=fh->fh_Device;
  86.         FreeDosObject(DOS_FILEHANDLE,fh);
  87.     }
  88.     }
  89.  
  90.     dl=LockDosList(LDF_DEVICES|LDF_ASSIGNS|LDF_WRITE);
  91.  
  92.     dl=FindDosEntry(dl,name,LDF_DEVICES|LDF_ASSIGNS);
  93.     if(dl==NULL)
  94.     {
  95.     if(newdl!=NULL)
  96.         AddDosEntry(newdl);
  97.     }else if(dl->dol_Type==DLT_DEVICE)
  98.     {
  99.     dl=newdl;
  100.     me->pr_Result2=ERROR_OBJECT_EXISTS;
  101.     success=0;
  102.     }else
  103.     {
  104.     RemDosEntry(dl);
  105.     if(newdl!=NULL)
  106.         AddDosEntry(newdl);
  107.     }
  108.  
  109.     if(dl!=NULL)
  110.     {
  111.     /* Prepare I/O request. */
  112.     iofs->IOFS.io_Message.mn_Node.ln_Type=NT_REPLYMSG;
  113.     iofs->IOFS.io_Message.mn_ReplyPort   =&me->pr_MsgPort;
  114.     iofs->IOFS.io_Message.mn_Length      =sizeof(struct IOFileSys);
  115.     iofs->IOFS.io_Device =dl->dol_Device;
  116.     iofs->IOFS.io_Unit   =dl->dol_Unit;
  117.     iofs->IOFS.io_Command=FSA_CLOSE;
  118.     iofs->IOFS.io_Flags  =0;
  119.  
  120.     /* Send the request. No errors possible. */
  121.     (void)DoIO(&iofs->IOFS);
  122.  
  123.     FreeDosEntry(dl);
  124.     }
  125.  
  126.     UnLockDosList(LDF_DEVICES|LDF_ASSIGNS|LDF_WRITE);
  127.  
  128.     return success;
  129.     __AROS_FUNC_EXIT
  130. } /* AssignLock */
  131.